<!DOCTYPE html>
<html>
<head>
  <title>Research software development</title>

  <link rel="stylesheet" href="/rsd/assets/css/main.css">
  <link rel="shortcut icon" type="image/png" href="/rsd/assets/favicon.ico"/>

  <link rel="stylesheet"
        href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
  <script
src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>

   
<style media="screen" type="text/css">


div.input_prompt {
  color: #303F9F;
}

div.output_prompt {
  color: #D84315;
}
</style>

    <!-- Loading mathjax macro -->
    <!-- Load mathjax -->
        <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
        <!-- MathJax configuration -->
        <script type="text/x-mathjax-config">
        MathJax.Hub.Config({
            tex2jax: {
                inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
                processEscapes: true,
                processEnvironments: true
            },
            // Center justify equations in code and markdown cells. Elsewhere
            // we use CSS to left justify single line equations in code cells.
            displayAlign: 'center',
            "HTML-CSS": {
                styles: {'.MathJax_Display': {"margin": 0}},
                linebreaks: { automatic: true }
            }
        });
        </script>
        <!-- End of mathjax configuration --></head>


    <!-- Google Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-38016329-2', 'auto');
    ga('send', 'pageview');
    </script>

</head>
<body>

    <header class="site-header">

  <div class="wrap">


    <nav class="site-nav">
      <a href="#" class="menu-icon">
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
           viewBox="0 0 18 15" enable-background="new 0 0 18 15" xml:space="preserve">
          <path fill="#505050" d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0
            h15.031C17.335,0,18,0.665,18,1.484L18,1.484z"/>
          <path fill="#505050" d="M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0c0-0.82,0.665-1.484,1.484-1.484
            h15.031C17.335,6.031,18,6.696,18,7.516L18,7.516z"/>
          <path fill="#505050" d="M18,13.516C18,14.335,17.335,15,16.516,15H1.484C0.665,15,0,14.335,0,13.516l0,0
            c0-0.82,0.665-1.484,1.484-1.484h15.031C17.335,12.031,18,12.696,18,13.516L18,13.516z"/>
        </svg>
      </a>
      <div class="trigger">
          <a class="page-link" href="/rsd/">RSD</a>
          <a class="page-link" href="/rsd/chapters/">Chapters</a>
          <a class="page-link" href="/rsd/extras/">Extras</a>
      </div>
    </nav>

  </div>
</header>

 <div class="page-content">
    <div class="wrap">
      <div class="home">
        
    <h1>The command line</h1>
<p>When using a computer we are mostly used to using a <em>graphical user interface</em>.
This is made up of icons and windows and is mainly interacted with using a
mouse. This is often referred to as a <em>point and click</em> approach.</p>
<p>One of the downsides of a <em>point and click</em> approach in the scope of
reproducible research is that giving instructions is often difficult and they
can be ambiguous.</p>
<p>Another approach is to use the command line. This is a small window in to which
we type commands and lets us give precise (reproducible) commands to the
computer.</p>
<h2>Identify and open your command line interface.</h2>
<p>First, it is important to note that this will now differ (but not substantially)
depending on whether or not you're on a Windows machine:</p>
<ul>
<li>Windows: we will choose to use <strong>Anaconda Prompt</strong> (which was installed on
  your machine when you installed Anaconda).</li>
<li>nix (another way to describe Mac OS and/or Linux machines): we will use the
  system <strong>terminal</strong>.</li>
</ul>
<h2>Finding your current location</h2>
<p>Let us first find out which directory (folder) we are currently in:</p>
<p><strong>Windows</strong></p>
<pre><code class="bash">cd
</code></pre>

<p>This stands for "current directory".</p>
<p><strong>nix</strong></p>
<pre><code class="bash">pwd
</code></pre>

<p>This stands for "present working directory"</p>
<ol>
<li>Type this command in</li>
<li>Press <code>Enter</code></li>
</ol>
<p>It should list where you are currently located in your
command line interface.</p>
<h2>Seeing what is in your current location</h2>
<p>To view the contents of the current directory:</p>
<p><strong>Windows</strong></p>
<pre><code class="bash">dir
</code></pre>

<p>This stands for "directory".</p>
<p><strong>nix</strong></p>
<pre><code class="bash">ls
</code></pre>

<p>This stands for "list"</p>
<ol>
<li>Type this command in.</li>
<li>Press <code>Enter</code></li>
</ol>
<p>You should see a list of the various files and directory in your current
directory.</p>
<p>Open your current directory in a graphical user interface and compare.</p>
<h2>Creating a directory</h2>
<p>To create a directory:</p>
<pre><code class="bash">mkdir &lt;directory_name&gt;
</code></pre>

<p>Experiment with creating a directory for this workshop:</p>
<pre><code class="bash">mkdir rsd-workshop
</code></pre>

<p>If your directory structure looked like this:</p>
<pre><code class="bash">|--- home/
     |--- research
     |--- photos
</code></pre>

<p>It will now look something like:</p>
<pre><code class="bash">|--- home/
     |--- research
     |--- photos
     |--- rsd-workshop
</code></pre>

<h2>Moving to another location</h2>
<p>On both Windows and nix if you want to enter a directory that is in your current
diractory type:</p>
<pre><code class="bash">cd &lt;directory&gt;
</code></pre>

<p>To move in to the <code>rsd-workshop</code> directory we created previously:</p>
<pre><code class="bash">cd rsd-workshop
</code></pre>

<p>As an exercise, move in to that directory and create two further directories:</p>
<pre><code>|--- rsd-workshop
     |--- tex
     |--- src

</code></pre>

<p>These two directories stand for LaTeX (<code>tex</code>) and source code (<code>src</code>): we will
use these later on in the course.</p>
<p>If you now wanted to go back to the "parent" directory:</p>
<pre><code class="bash">cd ..
</code></pre>

<p>Where <code>..</code> is short hand for a previous directory.</p>
<p>Experiment with these, in combination with the command to find your current
location as well as the command to list the contents of your directory.</p>
<h2>Copying files</h2>
<p>To copy a file:</p>
<p><strong>Windows</strong></p>
<pre><code class="bash">copy &lt;file&gt; &lt;new_file_directory_and_name&gt;
</code></pre>

<p><strong>nix</strong></p>
<pre><code class="bash">cp &lt;file&gt; &lt;new_file_directory_and_name&gt;
</code></pre>

<p>Experiment with copying <em>any</em> file.</p>
<h2>Moving/renaming files</h2>
<p>To move a file:</p>
<p><strong>Windows</strong></p>
<pre><code class="bash">move &lt;file&gt; &lt;new_file_directory_and_name&gt;
</code></pre>

<p><strong>nix</strong></p>
<pre><code class="bash">mv &lt;file&gt; &lt;new_file_directory_and_name&gt;
</code></pre>

<p>Experiment with moving <em>any</em> file.</p>
<p>Note that if you want to rename a file you can do this by passing the new name
in the same directory.</p>
<p><strong>WARNING</strong> When using the command line interface you will not be prompted for
confirmation if <code>move</code>/<code>mv</code> were to overwrite another file. Be careful.</p>
<h2>Deleting files</h2>
<p>To delete a file:</p>
<p><strong>Windows</strong></p>
<pre><code class="bash">del &lt;file&gt;
</code></pre>

<p><strong>nix</strong></p>
<pre><code class="bash">rm &lt;file&gt;
</code></pre>

<h2>Copying and removing directories</h2>
<p>To copy a directory:</p>
<p><strong>Windows</strong></p>
<pre><code>xcopy &lt;dir&gt; &lt;target&gt;
</code></pre>

<p><strong>nix</strong></p>
<pre><code>cp -r &lt;dir&gt; &lt;target&gt;
</code></pre>

<p>To remove a directory:</p>
<p><strong>Windows</strong></p>
<pre><code>rmdir /s &lt;dir&gt;
</code></pre>

<p><strong>nix</strong></p>
<pre><code>rm -r &lt;dir&gt;
</code></pre>

<h1>Tip: Tab completion</h1>
<p>Most command line tools allow for command tab completion. This means you can
start typing the first few letters of a file or a directory and press tab which
will complete the rest. This is a very useful tool to ensure you don't make
mistakes when typing.</p>
<p>You can also use the up/down arrow keys to cycle through your previous commands.
This also helps avoid repetitive typing.</p>

      </div>
  </div>
</div>


</body>
</html>